package cn.dnui_cr503.dnuifood_16110100503.model;

import cn.dnui_cr503.dnuifood_16110100503.listener.OnRetrofitListener;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by chengrui on 2018/10/31.
 */

public class BaseModel {
    public final static String BASE_URL="http://172.24.10.175:8080/foodService/";
    public Retrofit retrofit;
    public BaseModel(){
        retrofit=new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
    }
    public<T> void bindCallback(Call<T> call, final OnRetrofitListener<T>listener,final int flag){
        Callback<T> callback=new Callback<T>() {
            @Override
            public void onResponse(Call<T> call, Response<T> response) {
                listener.onSuccess(response.body(),flag);
            }

            @Override
            public void onFailure(Call<T> call, Throwable t) {
                listener.onFailure("解析有误");

            }
        };
        call.enqueue(callback);
    }
}
